﻿Imports System.Globalization

Module MainModule

    ' variables publiques pour la gestion du GPS
    Public m_isFormGPSOpen As Boolean = False
    Public m_strGpsDeviceIsOpen As Boolean = False
    Public m_isGpsInterpreteurOpen As Boolean = False
    Public oCurrentGpsPosition As ClsGpsPosition
    Public oCurrentListImg As ClsListImageProperties
    Public SeparateurDecimal As String = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator
    Public geoPictureDossier As String = "/My Documents/Photos_Georef/"
    Public oListObs As ClsListObservations
    Public oProtocolsCurrentListObs As Hashtable = Nothing
    Public oProtocolsOldListObs As Hashtable = Nothing

    Public Sub Main()
        Try
            REM Création de la fenêtre principale et affichage
            'Dim wFormMain As New FormMain
            'wFormMain.Show()
            Application.DoEvents()

            REM Creéation du splash screen et affichage
            Dim wSplash As New FormSplash
            wSplash.Show()

            REM On attend 5 secondes avant de continuer
            Dim wStart As TimeSpan = Now.TimeOfDay
            Do While Now.TimeOfDay.Subtract(wStart).Seconds < 3
                Application.DoEvents()
            Loop

            REM On ferme le splash screen
            FormSplash.Hide()
            FormSplash.Close()
            'FormMain.Show()
            REM On lance la fenêtre principale de l'application
            Application.Run(FormMain)

        Catch ex As Exception
            'En cas d'erreur
            '*******************************************
            'sauvegarde du track
            Try
                SaveTrack(FormMain.NSDossier & "TrackGPS_" & Now.ToString("yyMMdd") & ".gpx", FormMain.NSDossier, True)
            Catch exIn As Exception
                MsgBox(exIn.Message, MsgBoxStyle.Exclamation, "Pocket eRelevé")
            End Try

            '******************************************************
            'sauvegarde des données saisies s'il y en a !
            Try
                'Dim indice As Short
                Dim strKeyPr As String
                For Each de As DictionaryEntry In oProtocolsCurrentListObs
                    strKeyPr = de.Key
                    SaveObservation(FormMain.NSDossier, DirectCast(de.Value, ClsListObservations), strKeyPr)
                Next de


                'For Each oListObs In oProtocolsListObs
                '    ' recuperer l'indice de oListObs permettant de savoir quel est le protocole concerné
                '    indice = oProtocolsListObs.IndexOf(oListObs)
                '    SaveObservation(FormMain.NSDossier, oListObs, indice)
                'Next

            Catch exIn As Exception
                MsgBox(exIn.Message, MsgBoxStyle.Exclamation, "Pocket eRelevé")
            End Try

            MsgBox("Erreur fatale : " & ex.Message, MsgBoxStyle.Critical, "Pocket eReleve")
        End Try
        Cursor.Current = Cursors.Default
    End Sub

End Module
